package com.inexas.cu.server.core;

import static org.junit.Assert.*;
import org.junit.*;
import com.google.inject.*;
import com.inexas.cu.server.*;
import com.inexas.cu.stratus.*;

public class BuildTestCore {
	private static Injector factory;
	private Stratus stratus;

	@BeforeClass
	public static void initialize() {
		factory = Guice.createInjector(new TestModule());
	}

	
	@Before
	public void setup() {
		// Start with an empty database...
		stratus = factory.getInstance(Stratus.class); 
		//
	}
	
	@Test
	public void person() {
		final String firstName = "First";
		final String lastName = "Last";
		
		// Create a person...
		final Person lost = new Person(firstName, lastName);
		stratus.create(lost);

		// Find the person we just created...
		final Person found = stratus.findBy(	//
				Person.class,	//
				"firstName:'" + firstName + '\'');
		assertEquals(found.getFirstName(), lost.getFirstName());

		// Delete the person we just created...
		stratus.delete(found);
		
		final Person missing = stratus.findBy(	//
				Person.class,	//
				"firstName:'" + firstName + '\'');
		assertNull(missing);
	}
	
	public void account() {
		final String firstName = "First";
		final String lastName = "Last";
		final String accountName = "account";
		final String password = "password";
		
		// Create a person...
		final Person person = new Person(firstName, lastName);
		stratus.create(person);
		
		final Account account = new Account(person, accountName, password);
		stratus.create(account);

		final Account found = stratus.findBy(Account.class, "name:'" + accountName + '\'');
		assertEquals(found.getName(), accountName);
	}
	
}
